package day03;
import java.util.Arrays;

/*
@Author: 王少杰
@Date: 2025/1/2
@Time: 14:40
@FileName: Demo04.java
@描述:
面向对象
    封装:属性设置为私有的，提供公共的get、set方法供外部使用。
        把属性和对属性的操作，封装在类的内部，隐藏一些实现细节。外部通过暴露的方法访问属性。
        python中:__属性名 私有属性
        封装通过访问控制符来实现
        private:私有的，只能在类内部访问。
        default:默认的，不加控制符时表示是默认的。包访问权限，在当前包中访问。day03是一个包
        protected:受保护的，同一个包中其他类可以访问，不同包中它的子类可以访问。
        public:公共的，所有地方都可以访问。

    继承:

    多态:

    抽象:将多个有相同属性和行为的对象抽象成一个类型。创建类。
*/
public class Demo04 {
    public static void main(String[] args) {
        Car car = new Car();
        car.carNumber = "123";
        car.color = "red";
        car.rentPrice = 1000; //类外部可以随意设置属性的值
        car.buyPrice = 10000;
        car.rentPrice = -1000;
        System.out.println(car);



        Car1 car1 = new Car1("陕A66666","黑色",2000,10000);
        System.out.println(car1);
        car1.setColor("白色");
        car1.setRentPrice(100000);
        System.out.println(car1);
        System.out.println(car1.getColor());

        Car1[] cars = new Car1[5];//创建一个数组
        for (int i = 0;i < 5;i++){
            //创建一辆车
            Car1 car2 = new Car1("陕A6666" + i,"黑色",100 + i * 100,10000);
            //加入数组里面
            cars[i] = car2;
        }
        System.out.println(Arrays.toString(cars));

        //出租价格提升20%
        for (Car1 ca3:cars){
            int temp = (int) (ca3.getRentPrice() * 1.2f);
            ca3.setRentPrice(temp);
        }
        System.out.println("价格提升20%后");
        System.out.println(Arrays.toString(cars));
    }
}
class Car{
    //车牌号
    String carNumber;
    //车颜色
    String color;
    //出租金额
    int rentPrice;
    //购买金额
    int buyPrice;

    @Override
    public String toString() {
        return "Car{" +
                "车牌号='" + carNumber + '\'' +
                ", 车辆颜色='" + color + '\'' +
                ", 出租金额=" + rentPrice +
                ", 购买金额=" + buyPrice +
                '}';
    }

    public Car() {
    }

    public Car(String carNumber, String color, int rentPrice, int buyPrice) {
        this.carNumber = carNumber;
        this.color = color;
        this.rentPrice = rentPrice;
        this.buyPrice = buyPrice;
    }
}

class Car1{
     private String carNumber;//私有属性只能在类内部访问，类外部访问不了
    //车颜色
    private String color;
    //出租金额
    private int rentPrice;
    //购买金额
    private int buyPrice;

    public Car1() {
    }

    public Car1(String carNumber, String color, int rentPrice, int buyPrice) {
        this.carNumber = carNumber;
        this.color = color;
        this.rentPrice = rentPrice;
        this.buyPrice = buyPrice;
    }

    public String getCarNumber() {
        return carNumber;
    }

    public void setCarNumber(String carNumber) {
        this.carNumber = carNumber;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getRentPrice() {
        return rentPrice;
    }

    public void setRentPrice(int rentPrice) {
        this.rentPrice = rentPrice;
    }

    public int getBuyPrice() {
        return buyPrice;
    }

    public void setBuyPrice(int buyPrice) {
        this.buyPrice = buyPrice;
    }

    @Override
    public String toString() {
        return "Car1{" +
                "carNumber='" + carNumber + '\'' +
                ", color='" + color + '\'' +
                ", rentPrice=" + rentPrice +
                ", buyPrice=" + buyPrice +
                '}';
    }
}